<html>
<head><meta charset="utf-8"><title>musl toolchain and proc macros · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros.html">musl toolchain and proc macros</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="196863907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/musl%20toolchain%20and%20proc%20macros/near/196863907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros.html#196863907">(May 08 2020 at 07:06)</a>:</h4>
<p>It <a href="https://git.musl-libc.org/cgit/musl/tree/src/ldso/dlopen.c" title="https://git.musl-libc.org/cgit/musl/tree/src/ldso/dlopen.c">seems</a> to me that <code>dlopen</code> does not quite work on musl. But there is a musl Rust toolchain -- does anyone know how it's working?</p>



<a name="196870088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/musl%20toolchain%20and%20proc%20macros/near/196870088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros.html#196870088">(May 08 2020 at 08:34)</a>:</h4>
<p>It seems that you need to disable crt-static (link musl dynamically) to get it working: <a href="https://github.com/rust-lang/rust/issues/31322" title="https://github.com/rust-lang/rust/issues/31322">https://github.com/rust-lang/rust/issues/31322</a></p>



<a name="196994578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/musl%20toolchain%20and%20proc%20macros/near/196994578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros.html#196994578">(May 09 2020 at 14:37)</a>:</h4>
<p>Starting with 1.44 beta you shouldn't need anything special to make it work: <a href="https://github.com/rust-lang/rust/issues/40174" title="https://github.com/rust-lang/rust/issues/40174">https://github.com/rust-lang/rust/issues/40174</a></p>



<a name="196995481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/musl%20toolchain%20and%20proc%20macros/near/196995481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros.html#196995481">(May 09 2020 at 14:56)</a>:</h4>
<p>But, with <code>-crt-static</code>, the rust-analyzer itself would require <code>musl</code> to be present on the user's machine, right? </p>
<p>Like, it seems like it's fundamentally impossible to statically link libc, but be able to dlopen dynamic libraries, because the main executable and the loaded library need to use the same (dynamically loaded) libc?</p>



<a name="197001100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/musl%20toolchain%20and%20proc%20macros/near/197001100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros.html#197001100">(May 09 2020 at 17:02)</a>:</h4>
<blockquote>
<p>But, with <code>-crt-static</code>, the rust-analyzer itself would require <code>musl</code> to be present on the user's machine, right? </p>
</blockquote>
<p>Correct. <a href="https://github.com/rust-lang/rust/pull/69519" title="https://github.com/rust-lang/rust/pull/69519">https://github.com/rust-lang/rust/pull/69519</a> gets around that by setting <code>-crt-static</code> only for proc_macros (which are only used during compilation). This only takes effect on musl based systems, on glibc systems proc_macros are build for <code>${arch}-unknown-linux-gnu</code> target.</p>
<blockquote>
<p>Like, it seems like it's fundamentally impossible to statically link libc, but be able to dlopen dynamic libraries, because the main executable and the loaded library need to use the same (dynamically loaded) libc?</p>
</blockquote>
<p>Yes, AFAIK.</p>



<a name="197011738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/musl%20toolchain%20and%20proc%20macros/near/197011738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros.html#197011738">(May 09 2020 at 20:38)</a>:</h4>
<p>It's more or less safe to do so, as long as you don't resolve any network names or user names or similar; a statically linked glibc still dynamically loads NSS modules.</p>



<a name="197024309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/musl%20toolchain%20and%20proc%20macros/near/197024309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros.html#197024309">(May 10 2020 at 01:04)</a>:</h4>
<p>I'm going to revert <a href="https://github.com/rust-lang/rust/pull/69519" title="https://github.com/rust-lang/rust/pull/69519">https://github.com/rust-lang/rust/pull/69519</a> though and do it in a slightly more general and more conservative way.</p>



<a name="197024373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/musl%20toolchain%20and%20proc%20macros/near/197024373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros.html#197024373">(May 10 2020 at 01:07)</a>:</h4>
<p>Just need to finish some reading - <a href="https://gist.github.com/petrochenkov/1a2e52b01a71d49d908756e194d3c3d9" title="https://gist.github.com/petrochenkov/1a2e52b01a71d49d908756e194d3c3d9">https://gist.github.com/petrochenkov/1a2e52b01a71d49d908756e194d3c3d9</a>. This is a truly wonderful story.</p>



<a name="197024533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/musl%20toolchain%20and%20proc%20macros/near/197024533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros.html#197024533">(May 10 2020 at 01:12)</a>:</h4>
<p>The sooner the better, <a href="https://github.com/rust-lang/rust/pull/69519" title="https://github.com/rust-lang/rust/pull/69519">https://github.com/rust-lang/rust/pull/69519</a> is harmful for future-compatibility (besides just being hacky).</p>



<a name="197060332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/musl%20toolchain%20and%20proc%20macros/near/197060332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros.html#197060332">(May 10 2020 at 15:09)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123856">Vadim Petrochenkov</span> <a href="#narrow/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros/near/197024533" title="#narrow/stream/131828-t-compiler/topic/musl.20toolchain.20and.20proc.20macros/near/197024533">said</a>:</p>
<blockquote>
<p><a href="https://github.com/rust-lang/rust/pull/69519" title="https://github.com/rust-lang/rust/pull/69519">https://github.com/rust-lang/rust/pull/69519</a> is harmful for future-compatibility</p>
</blockquote>
<p>Strike that, <a href="https://github.com/rust-lang/rust/issues/69519" title="https://github.com/rust-lang/rust/issues/69519">#69519</a> only allows proc macro crates if <code>crt-static = true</code> comes from target defaults, but not from explicitly passed options.<br>
Phew.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>